# Figure 2. Triangle plot of topic frequency by question 


library(stm)
library(ggtern)

# load data
path <- "P:/2017-pathways/new/4-model-output"
setwd(path)
load("pathwaysPrevFit9.Rdata")

# Triangle plot
triangle<-as.data.frame(colSums(pathwaysPrevFit9$theta[meta_o_p_data$treatment==1,])/1040)
names(triangle)[1]<-paste("OilGas")
triangle$Energy <- colSums(pathwaysPrevFit9$theta[meta_o_p_data$treatment==2,])/964
triangle$Transition <- colSums(pathwaysPrevFit9$theta[meta_o_p_data$treatment==3,])/942
triangle$Topic<- c(
  "Energy sources", 
  "Alternatives to oil", 
  "Crisis", 
  "End of era", 
  "Work life changes",
  "Lofoten", 
  "Dependence",
  "Fossil-renewable",
  "Political/economic changes")
shapes<-c(21,22,23,24,25,26,27,28,29)

ggtern(data = triangle, aes(x = OilGas, y = Energy, z = Transition)) +
  geom_point(aes(fill = Topic, shape=Topic),
             # geom_point(aes(shape=Topic, color=Topic),
             size = 5, color="black") +
  labs(fill = "Topic") +
  theme_bw() +
  theme(legend.position = c(0,1),
        legend.justification = c(1, 1)) +
  limit_tern(1.1,1.1,1.1)+
  scale_shape_manual(values=seq(0,9)) 
